#ifndef _UORB_H
#define _UORB_H

#include "stm32f10x.h"

typedef void 	*orb_advert_t;
#ifndef bool
#define  bool uint8_t
#endif

#define ORB_ID(_name)		&__orb_##_name

typedef struct orb_subscriber
{
	uint32_t id;
	uint8_t flag;
	
	struct orb_subscriber * next;
} orb_subscriber;

/**
 * Object metadata.
 */
struct orb_metadata {
	const char *o_name;		/**< unique object name */
	const long unsigned int o_size;		/**< object size */
	
	int metadata_nums;
	orb_subscriber *subscriber_first;
	void *orb_data;
};



/**
 * Define (instantiate) the uORB metadata for a topic.
 *
 * The uORB metadata is used to help ensure that updates and
 * copies are accessing the right data.
 *
 * Note that there must be no more than one instance of this macro
 * for each topic.
 *
 * @param _name		The name of the topic.
 * @param _struct	The structure the topic provides.
 * @param _size_no_padding	Struct size w/o padding at the end
 * @param _fields	All fields in a semicolon separated list e.g: "float[3] position;bool armed"
 */
#define ORB_DEFINE(_name, _struct)		\
	 struct orb_metadata __orb_##_name = {	\
		#_name,					\
		sizeof(_struct),		\
		0,						\
		0,						\
		0						\
	}; 


/**
 * Declare (prototype) the uORB metadata for a topic (used by code generators).
 *
 * @param _name		The name of the topic.
 */
//#if defined(__cplusplus)
//# define ORB_DECLARE(_name)		extern "C" const struct orb_metadata __orb_##_name __EXPORT
//#else
# define ORB_DECLARE(_name)		extern struct orb_metadata __orb_##_name 
//#endif






bool orb_advertise(struct orb_metadata *meta);
bool orb_subscribe(struct orb_metadata *meta,uint32_t *id);
bool orb_unsubscribe(struct orb_metadata *meta,uint32_t *id);
bool orb_check(struct orb_metadata *meta,uint32_t id);
bool orb_copy(struct orb_metadata *meta,void *buffer);
bool orb_publish(struct orb_metadata *meta,void *structure);






#endif

